package com.example.domain.vo;
 import com.alibaba.fastjson.annotation.JSONField;
 import com.example.domain.User;
 import lombok.Data;
 import lombok.NoArgsConstructor;
 import org.springframework.security.core.GrantedAuthority;
 import org.springframework.security.core.authority.SimpleGrantedAuthority;
 import org.springframework.security.core.userdetails.UserDetails;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.List;

@Data
 @NoArgsConstructor
// @AllArgsConstructor
 public class LoginUser implements UserDetails {
   //传入的参数权限列表
 private List<String> list;
 private User user;
 public LoginUser(User user,List<String> list){
  this.user=user;
  this.list=list;
 }
 //自定义一个权限列表的集合
 @JSONField(serialize = false)
 List<SimpleGrantedAuthority> authorities;//子类
 //权限列表，用来返回权限信息
@Override
 public Collection<? extends GrantedAuthority> getAuthorities() {
 if(authorities!=null){
  return authorities;
 }
 authorities= new ArrayList<>();
 for (String item : list) {
    SimpleGrantedAuthority authority = new SimpleGrantedAuthority(item);
    authorities.add(authority);
 }
 return authorities;
 }
 //获取密码
@Override
 public String getPassword() {
 return user.getPassword();
 }
//获取用户名
@Override
 public String getUsername() {
 return user.getUserName();
 }
 //判断账号是否未过期
@Override
 public boolean isAccountNonExpired() {
 return true;
 }
 //判断账号是否没有锁定
@Override
 public boolean isAccountNonLocked() {
 return true;
 }
 //判断账号是否没有超时
@Override
 public boolean isCredentialsNonExpired() {
 return true;
 }
 //判断账号是否可用
@Override
 public boolean isEnabled() {
 return true;
 }
 }